package com.jmall.user.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import com.jmall.base.UserException;
import com.jmall.user.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	@Resource(name="userService")
	private UserService userService = null;
	@RequestMapping("/login")
	
	public String login(String username,String password,WebRequest wr){
		try {
		//当前登录人的信息
		Map user = userService.checkLogin(username, password);
		//将当前登录人的信息存放在Session.loginuser属性中
		wr.setAttribute("loginuser", user, WebRequest.SCOPE_SESSION);
		return "/home.html";
		} catch (UserException e) {
			// TODO: handle exception
		wr.setAttribute("error_message", e.getMessage(), WebRequest.SCOPE_REQUEST);
		return "/login.jsp";
		}
	}
}
